import { IExplore, IOperate, IDir } from './explore.defind';
import {data} from '../fake-data';
import { showLetter, readFileList, orderFile } from '../../../lib/file-system';
const path = (<any>window).require('path');
const fs = (<any>window).require('fs');
export class LocalExplore implements IExplore, IOperate{
    public name: string = '本地';
    public dirs: IDir[] = [];
    public choosedPath: string = '';
    constructor() {
        showLetter((res) => {
            console.log(res);
        });
    }
    public toggleFloderStatus(dir: IDir) {
        if(dir.isClose == true) {
            dir.isClose = false;
            let children: IDir[] = [];
            console.log(path.resolve(dir.desk + dir.fullPath))
            readFileList(path.resolve(dir.fullPath), children, '/', 1);
            dir.children = orderFile(children, (t) => {
                t.desk = dir.desk;
                t.isClose = true;
            });
            console.log(dir)
        }else{
            dir.isClose = true;
        }
    }
    public async init(): Promise<LocalExplore> {
        // this.dirs = data.data;
        return new Promise(resolve => {
            showLetter((res) => {
                for(let item of res) {
                    this.dirs.push({
                        desk: item+':/',
                        isClose: true,
                        isDir: true,
                        name: item+':/',
                        fullPath: '/',
                        children: []
                    })
                }
                resolve(this);
            });            
        });
    }
    public selectPath(dir: IDir) {
        if(dir.isDir == true) {
            this.choosedPath = dir.fullPath;
        }
    }
}